package com.daon.service.impl;

import com.daon.common.RequestHolder;
import com.daon.dao.SysRoleMapper;
import com.daon.dao.SysRoleUserMapper;
import com.daon.dto.SysRoleDto;
import com.daon.pojo.SysRole;
import com.daon.pojo.SysRoleUser;
import com.daon.service.ISysRoleUserService;
import com.google.common.collect.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author 1daon
 * @EMAIL 532418116@qq.com
 * @Version 创建时间：2019/3/16 9:08 PM
 * @Modified By
 */
@Service("iSysRoleUserService")
public class SysRoleUserServiceImpl implements ISysRoleUserService {
    @Autowired
    private SysRoleUserMapper sysRoleUserMapper;
    @Autowired
    private SysRoleMapper sysRoleMapper;
    @Override
    public List<SysRoleDto> getRoleUserByUserId(int userId) {
        List<SysRoleUser> sysRoleUserList = sysRoleUserMapper.selectRoleUserByUserId(userId);
        List<SysRole> sysRoleList = sysRoleMapper.sysRoleList();
        List<SysRoleDto> sysRoleDtoList = Lists.newArrayList();
        for (SysRole sysRole:sysRoleList){
            SysRoleDto dto = SysRoleDto.adapt(sysRole);
            for(SysRoleUser sysRoleUser:sysRoleUserList){
                if(sysRole.getRoleId() == sysRoleUser.getRoleId()){
                    dto.setChecked(true);
                }
            }
            sysRoleDtoList.add(dto);
        }
        return sysRoleDtoList;
    }
}
